$(function(){
	var i = 1;
	doPost();
	function doPost(){
		fetch('./list.do?type=json&page='+ i + '', {credentials: 'same-origin'})
		.then(function(response){
			return response.json();
		})
		.then(function(articles){
			var j = 1;
			var $div = $('#accordion');
			articles.forEach(function(art){
				
				$div.append('<div class="panel panel-default">'
						+ '<div class="panel-heading" role="tab" id="heading_' + j + '">'
						+ '<h4 class="panel-title">'
						+ '<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse_' + j + '" aria-expanded="false" aria-controls="collapse_' + j + '">' + art.title + '</a>'
						+ '<a class="nav navbar-nav navbar-right" href="#hui4">回复</a>'
						+ '</h4>'
						+ '</div>'
						+ '<div id="collapse_' + j + '" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_' + j + '">'
						+ '<div class="panel-body"><p>user:&nbsp;' + art.username + '&nbsp;&nbsp;&nbsp;&nbsp;' + 'time: &nbsp;' + art.publishDate + '</p>' + art.content + '</div>'
						+ '<div class="reply">' + '<h5>发表回复</h5>' + '<div class="reply_content">'
						+ '<textarea class="form-control" rows="8" name="content" id="content" placeholder="开通超级会员发帖6倍经验，错过这村可没这店哦。"></textarea>'
						+ '<button type="submit" class="btn btn-primary btn-block">发表</button></div></div>'
						+ '</div>'
						+ '</div>');
				j++;
			})
		})
	}
	$(document).mousemove(function(e) {
		if($(document).scrollTop() + $(window).height() >= $(document).height()) {
			i++;
			doPost();
		}
	});
})